package com.aigou.admin.service.impl;

import com.aigou.admin.dao.ShopCartDAO;
import com.aigou.admin.dao.impl.ShopCartDAOImpl;
import com.aigou.admin.entity.PageEntity;
import com.aigou.admin.entity.ShopCart;
import com.aigou.admin.service.ShopCartService;

import java.util.List;

public class ShopCartServiceImpl implements ShopCartService {

    private ShopCartDAO shopCartDAO = new ShopCartDAOImpl();
    @Override
    public int addShopCart(ShopCart shopCart) {
        return shopCartDAO.addShopCart(shopCart);
    }

    @Override
    public int deleteShopCart(String id) {
        return shopCartDAO.deleteShopCart(id);
    }

    @Override
    public ShopCart getShopCartById(String id) {
        return shopCartDAO.getShopCartById(id);
    }

    @Override
    public List<ShopCart> getAllShopCarts() {
        return shopCartDAO.getAllShopCarts();
    }

    @Override
    public int updateShopCart(ShopCart shopCart) {
        return shopCartDAO.updateShopCart(shopCart);
    }

    @Override
    public PageEntity<ShopCart> findShopCartPage(Integer current, Integer pageSize) {

        // 查询总记录数
        int total = shopCartDAO.selectShopCartCount();
        // 查询当前页数据
        List<ShopCart> shopCarts = shopCartDAO.selectShopCartLimits((current - 1) * pageSize, pageSize);
        // 包装数据发送给前端
        PageEntity<ShopCart> pageEntity = new PageEntity<>();
        pageEntity.setCurrent(current);
        pageEntity.setPageSize(pageSize);
        pageEntity.setTotal(total);
        pageEntity.setRecords(shopCarts);
        return pageEntity;
    }

}
